home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / winder2.zip / WINDERS.C < prev    next >
C/C++ Source or Header  |  1992-05-15  |  9KB  |  313 lines

  1. /*
  2.  
  3. Written By:    Earl W. Hartsell
  4.  
  5. Date:        5 - 15 - 92
  6.  
  7. Name:        WINDERS
  8.  
  9. Version:        2.0
  10.  
  11. Use:        Winders allows the user to choose to automatically run
  12.         windows or exit to dos upon startup or reboot.
  13.         It allows the user to specify a length of time to
  14.         countdown before Windows 3.X is loaded.
  15.         Windows may be loaded before the countdown
  16.          is complete by pressing one of the modifier keys
  17.         ([SHIFT], [ALT], or [CTRL]), the user may also
  18.         exit to DOS pressing any other key.
  19.  
  20. The syntax for the command is as follows:
  21.  
  22. d:\<path>\winders [num] [/d <location>] [/b] [/i] [/n] [/a <args>]
  23. d:\<path>\winders /h | /?
  24.  
  25. d:\<path>\     is drive and directory path where winders executable is
  26.         located.
  27.  
  28. num         is length of pause before loading windows.  It must be
  29.         first argument and may be range of 1 to 32767 in seconds.
  30.         The default pause is 5 seconds.  0 seconds defaults to 5.
  31.  
  32. /d <location>     is to specify drive and directory(s) in which
  33.         windows\win.com is located default is c: .
  34.         The location is not optional and will generate an error if
  35.         not found after the /d. There also must be a space between
  36.         the /d and the <location>.  If you use the /d option
  37.         it must contain the drive and all directories leading to
  38.         the \windows\win.com in this form:
  39.             drive:\dir1\dir2\...\dirn
  40.         The final back-slash is not required.
  41.  
  42. /b         beep on countdown, default no beep.
  43.  
  44. /i         suppress loading windows into screen. Default don't load
  45.         intro.
  46.  
  47. /a <args>    are the arguments to be passed to windows. The arguments are
  48.         not optional and will generate an error if not found after
  49.         the /a. There also must be a space between the /a and the
  50.         <args> and multiple arguments must be placed inside
  51.         quotes.  If you have problems getting this to work
  52.                 try using full path names on the executables.
  53.  
  54. /n        dont print winders countdown banner.
  55.         default print banner.
  56.  
  57. /v        prints out version and copyright information.
  58.  
  59. /h | /?        help screen.
  60.  
  61. Copyright (c) 1992 by VOLUNTEER SOFTWARE AND CONSULTING.
  62.  
  63. Permission granted to use, copy, and modify this in any way as long as
  64. the above copyright notice and address remain.
  65. Plese see the file called README for full details.
  66.  
  67. Windows is a registered trademark of Microsoft Corporation.
  68.  
  69. */
  70.  
  71. #include <stdio.h>
  72. #include <conio.h>
  73. #include <process.h>
  74. #include <time.h>
  75. #include <bios.h>
  76.  
  77. #define RIGHT          0x01
  78. #define LEFT           0x02
  79. #define CTRL           0x04
  80. #define ALT            0x08
  81. #define HLP            1
  82. #define DOS         2
  83. #define WIN         3
  84. #define null(x) strcpy(x,"")
  85.  
  86. char copy[] = "Copyright (c) 1992 VOLUNTEER SOFTWARE AND CONSULTING.\n";
  87. char right[] = "Permission is granted to use, copy, and modify as long as\n copyright notice remain.\n";
  88.  
  89. int main(argc, argv)
  90. int argc;
  91. char *argv[];
  92. {
  93.   int  pause = 5;             /* default pause */
  94.   int  i = 0, k = 0, j = 0;
  95.   char banner = 1;                       /* print banner flag */
  96.   char beep = 0;             /* set default beep off */
  97.   char arg1[100], arg2[100];         /* arguments to execl */
  98.   char intro = 1;             /* turn intro screen off */
  99.   char cdrive = 1;             /* default disk */
  100.   time_t start, new;             /* long int */
  101.  
  102.   fflush(stdin);     /* clear the kbd buffer */
  103.   null(arg2);         /* argument to pass to windows default none */
  104.  
  105.   if (atoi(argv[1]) > 0)  /* take first argument as number */
  106.   {
  107.     j = 2; 
  108.     pause = atoi(argv[1]);
  109.   }
  110.   else
  111.   {
  112.    j = 1;
  113.     pause = 5;
  114.   }
  115.   for (; j < argc; j++)
  116.   {
  117.     switch (argv[j][1])
  118.     { 
  119.       case 'v':
  120.         clrscr();
  121.         fprintf(stderr,"\n");
  122.     fprintf(stderr,"\t\t\tWINDERS VERSION 2.0\n");
  123.     fprintf(stderr,"%s",copy);
  124.     fprintf(stderr,"%s",right);
  125.     fprintf(stderr,"\n");
  126.  
  127.       case 'h': case '?':
  128.         fprintf(stderr,"\t\t\tWINDERS HELP\n");
  129.     fprintf(stderr,"%s [num] [/d location] [/b] [/a args] [/n] [/i]\n",argv[0]);
  130.     fprintf(stderr,"%s /h | /? for this help screen.\n",argv[0]);
  131.     fprintf(stderr,"%s /v for version and copyright information.\n\n",argv[0]);
  132.     fprintf(stderr,"num is duration of pause. default 5.  Num must be first argument.\n");
  133.     fprintf(stderr,"/d  location is to specify drive and directory(s) in which \\windows\\win.com \n");
  134.     fprintf(stderr,"    is located default is c: \n");
  135.     fprintf(stderr,"/b  is beep on countdown, default no beep.\n");
  136.     fprintf(stderr,"/i  is to suppress loading windows intro screen.  Default do not show intro.\n");
  137.     fprintf(stderr,"/n  dont print winders countdown banner.  Default is print banner.\n");
  138.     fprintf(stderr,"/a  is the argument(s) to be passed to windows.\n");
  139.         fprintf(stderr,"/h  and /?  print out this screen.\n\n");
  140.         fprintf(stderr,"Pressing [SHIFT], or [ALT], or [CTRL] during the countdown\n");
  141.         fprintf(stderr,"will cause Windows to load that instant.\n");
  142.         fprintf(stderr,"Pressing any other key will cause Winders to exit to DOS.\n");
  143.     fprintf(stderr,"\n");
  144.     exit(HLP);
  145.       break; /* help screen */
  146.  
  147.       case 'd':
  148.         if ( argv[j+1] == NULL || argv[j+1][0] == '/' )
  149.     {
  150.       fprintf(stderr,"\n");
  151.       fprintf(stderr,"%s: error in location option no arguments found.\n",argv[0]);
  152.       fprintf(stderr,"%s: option /d ignored.\n",argv[0]);
  153.           delay(2000);
  154.       /* error no argument found to pass to windows */
  155.       }
  156.     else
  157.     {
  158.       cdrive = 0;
  159.       strcpy(arg1, argv[++j]);
  160.     }
  161.       break;
  162.  
  163.       case 'n': 
  164.         banner = 0; /* dont print countdown banner */
  165.       break;
  166.  
  167.       case 'b': 
  168.         beep = 1;  /* set beep on */
  169.       break;
  170.  
  171.       case 'i': 
  172.         intro = 0;  /* turn on intro screen */
  173.       break;
  174.  
  175.       case 'a':
  176.     if ( argv[j+1] == NULL || argv[j+1][0] == '/' )
  177.     {
  178.       fprintf(stderr,"\n");
  179.       fprintf(stderr,"%s: error in argument option no arguments found.\n",argv[0]);
  180.       fprintf(stderr,"%s: option /a ignored.\n",argv[0]);
  181.           delay(2000);
  182.       /* error no argument found to pass to windows */
  183.     }
  184.     else
  185.     {
  186.       strcpy(arg2, argv[++j]); /* pass arguments */
  187.     }
  188.       break;
  189.       default: 
  190.         fprintf(stderr,"\n");
  191.         fprintf(stderr,"%s: Argument %s not recognized\n",argv[0],argv[j]); 
  192.     fprintf(stderr,"%s: Argument ignored.\n",argv[0]);
  193.     delay(2000);
  194.     }
  195.   }
  196.  
  197.   
  198.   k = keyhit();     /* check and see if key has already been selected */
  199.  
  200.   if (k == 1) Winf(arg1,arg2,cdrive,intro);
  201.   if (k == 2) Dosf();     /* exit to dos if key is pressed */
  202.  
  203.   clrscr(); /* clear screen */
  204.   if (banner)
  205.   {
  206.   printf("\t\t\t╔═══════════════════════════╗\n");
  207.   printf("\t\t\t║      Winders Countdown    ║\n");
  208.   printf("\t\t\t╚═══════════════════════════╝\n\n");
  209.   }
  210.   printf("\t\t       Loading Windows in %d seconds.\n",pause);
  211.   printf("\t Press [SHIFT], or [ALT], or [CTRL] to load Windows now.\n");
  212.   printf("\t\t      Press any other key to exit to DOS.\n");  /* print banner */
  213.   printf("\t\t\t\t  Counting");
  214.   start = time(NULL); /* get initial time in seconds */
  215.   for (i=1 ;(i <= pause && !k);i++)
  216.   {
  217.     new = time(NULL);         /* get new time */
  218.     while(new - start == 0)     /* start time = new time second not elapsed */
  219.     {
  220.       new = time(NULL);     /* get new time again */
  221.       k = keyhit();  if (k) break;
  222.     }
  223.     if (k == 1) Winf(arg1,arg2,cdrive,intro);
  224.     if (k == 2) Dosf();     /* exit to dos if key is pressed */
  225.     if (new - start != 0)
  226.     {
  227.       if (beep)
  228.     printf("\a.");
  229.       else
  230.     printf(".");
  231.     }
  232.     start = new;
  233.   }
  234.   Winf(arg1,arg2,cdrive,intro);
  235.   return (0); /* keeping the compiler happy */
  236. }
  237.  
  238. /* 
  239.     keyhit- function returns 0,1, or 2 depending on the key pressed
  240.     0 - if no key has been pressed
  241.     1 - if SHIFT, CTRL, or ALT has been pressed
  242.     2 - if a key other than the ones above has been pressed
  243. */
  244.  
  245. int keyhit(void)
  246. {
  247.   int modifiers;
  248.  
  249.   modifiers = bioskey(2);
  250.   if (modifiers)
  251.   {
  252.     if (modifiers & RIGHT) return(1);
  253.     if (modifiers & LEFT)  return(1);
  254.     if (modifiers & CTRL)  return(1);
  255.     if (modifiers & ALT)   return(1);
  256.   }
  257.   if (bioskey(1)) return(2);
  258.   return(0);
  259. }
  260.  
  261. /* Dosf - return to DOS and clear screen */
  262.  
  263. Dosf(void)
  264. {
  265.     fflush(stdout);
  266.     clrscr();
  267.     exit(DOS);
  268.     return(DOS); /* it will never make it here but it will keep the compiler */
  269.          /* happy. */
  270. }
  271.  
  272. /* Winf - execute win.com and pass arguments to it. 
  273.  
  274.    arg1 - 
  275.  
  276.    arg2 - arguments passed to WIN.COM
  277.  
  278.    cdrive - 0 use drive specified 
  279.             1 use default drive
  280.  
  281.    intro - 0 will by pass Windows intro using command win :
  282.            1 (default) Will show intro screen  
  283.    
  284.    Note: execl was used in the hope that the progam would be
  285.          cleared from memory and not take up any space in Windows.
  286. */
  287.  
  288. Winf(arg1, arg2, cdrive, intro)
  289. char arg1[], arg2[];
  290. char cdrive, intro;
  291. {
  292.   char cmd_part2[30];
  293.  
  294.   strcpy(cmd_part2,"\\windows\\win.com"); /* win.com must be in */
  295.                       /* \windows\win.com   */
  296.  
  297.   printf("\n\t\t\t      Loading Windows...");
  298.  
  299.   if (cdrive)
  300.   {
  301.     strcpy(arg1,"c:"); /* default to c drive */
  302.     strcat(arg1,cmd_part2);
  303.   }
  304.   else
  305.     strcat(arg1,cmd_part2);  /* use drive specified */
  306.  
  307.   if (intro) /* to show into or not to show intro */
  308.     execl(arg1,"win",":",arg2,NULL);
  309.   else
  310.     execl(arg1,"win",arg2,NULL);
  311.  
  312.   return(WIN);
  313. }